import java.util.Random;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: Zguoxu
 * Date: 2025-02-16
 * Time: 16:56
 */
public class Test {
    public static void main(String[] args) {

    }
    public static void main6(String[] args) {
        //求2个整数的最大公约数
        System.out.println("m = ");

        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();

        System.out.println("n = ");
        int n = scan.nextInt();

        int k = m % n;
        while (m % n != 0) {
            m = n;
            n = k;
            k = m % n;
        }
        System.out.println(n);
    }
    public static void main5(String[] args) {
        //输出一个整数的每一位
        System.out.println("请输入一个整数：");

        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();

        while (num != 0) {
            System.out.println(num % 10);
            num /= 10;
        }
    }
    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int num = in.nextInt();
            for (int i = 0; i < num; i++) {
                for (int j = 0; j < num; j++) {
                    if (i == j || i + j == num - 1) {
                        System.out.print('*');
                    } else {
                        System.out.print(' ');
                    }
                }
                System.out.print('\n');
            }
        }
    }
    public static void main3(String[] args) {
        //猜数字游戏
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        int randNum = random.nextInt(101);

        while (true) {
            System.out.println("请输入你猜的数字:");
            int num = scan.nextInt();

            if (num < randNum) {
                System.out.println("猜小了");
            } else if (num == randNum) {
                System.out.println("猜对了");
                break;
            } else {
                System.out.println("猜大了");
            }
        }
    }
    public static void main2(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        int flag = 1;
        double sum = 0.0;
        for (int i = 1; i <= 100; i++) {
            sum += flag * (1.0 / i);
            flag = -flag;
        }
        System.out.println(sum);//0.688172179310195
    }
    public static void main1(String[] args) {
        //编写程序数一下 1到 100 的所有整数中出现多少个数字9
        int sum = 0;
        for (int num = 1; num <= 100; num++) {
            int count = 0;
            int tmp = num;
            while (tmp != 0) {
                if (tmp % 10 == 9) {
                    count++;
                }
                tmp /= 10;
            }
            sum += count;
        }
        System.out.println(sum);//20
    }
}
